package com.hongx.zhibo;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.hongx.zhibo.utils.MagicTextView;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;

import java.util.List;

public class NewAdapter extends CommonAdapter<ItemBean> {

    private final TranslateAnimation inAnim;
    private final TranslateAnimation outAnim;

    public NewAdapter(Context context, List<ItemBean> datas) {
        super(context, R.layout.item_gift, datas);
        inAnim = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.gift_in); // 礼物进入时动画

        outAnim = (TranslateAnimation) AnimationUtils.loadAnimation(context, R.anim.gift_out); // 礼物退出时动画
    }

    @Override
    protected void convert(ViewHolder holder, ItemBean itemBean, int position) {
        holder.itemView.clearAnimation();

        if (itemBean.type == 0) {
            View view = holder.getView(R.id.root_layout);
            view.clearAnimation();
            TranslateAnimation animation = (TranslateAnimation) AnimationUtils.loadAnimation(mContext, R.anim.gift_out);
            view.setAnimation(animation);
           animation.setAnimationListener(new Animation.AnimationListener() {
               @Override
               public void onAnimationStart(Animation animation) {

               }

               @Override
               public void onAnimationEnd(Animation animation) {
                   view.setVisibility(View.INVISIBLE);
               }

               @Override
               public void onAnimationRepeat(Animation animation) {

               }
           });
           // view.setVisibility(View.INVISIBLE);
            return;
        }
        holder.getView(R.id.root_layout).setVisibility(View.VISIBLE);
        ImageView gitview = holder.getView(R.id.iv_gift);
        gitview.setImageResource(itemBean.gifId);
        MagicTextView mv = holder.getView(R.id.mtv_giftNum);
        mv.setText("x" + itemBean.count);
    }


}
